package com.liu.homeWork;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class HomeWork02 {
    public static void main(String[] args) throws IOException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        Class<?> cls = Class.forName("java.io.File");
        Constructor<?>[] declaredConstructors = cls.getDeclaredConstructors();
        for (Constructor<?> constructor : declaredConstructors) {
            constructor.setAccessible(true);
            System.out.println(constructor);
        }
        //public java.io.File(java.lang.String)指定构造器
        Constructor<?> declaredConstructor = cls.getDeclaredConstructor(String.class);
        String filePath = "d:\\a.txt";
        Object file = declaredConstructor.newInstance(filePath);
        //得到createNewFile方法
        Method methods = cls.getMethod("createNewFile");
        methods.invoke(file);

    }
}
